package com.billionsfinance.hessian.common.zookeeper.client;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * @ FileName: ClientSideZkEventQueue.java
 * @ Author: WeiHui-Z
 * @ Date: 2016-11-21  14:31
 * @ Version: v1.0.0
 */
public class ClientSideZkEventQueue {

	private static BlockingQueue<ClientSideZkEvent> queue = new LinkedBlockingDeque<>();

	/**
	 * 循环直到放进队列
	 *
	 * @param event 事件
	 */
	public static void put(ClientSideZkEvent event) {
		for (; ; ) {
			try {
				queue.put(event);
				return;
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * 循环直到取到值
	 *
	 * @return 事件
	 */
	public static ClientSideZkEvent take() {
		for (; ; ) {
			try {
				return queue.take();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

}
